import { createStore } from 'vuex'

export default createStore({
  state: {
    user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : '',
    token: localStorage.getItem('token') ? localStorage.getItem('token') : '',
    config: {},
    loading: false,
    isThirdRouter: false,
    isFirstRouter: '',
    // rememberUser: localStorage.getItem('rememberUser')&&localStorage.getItem('rememberUser')=='true' || false,
    language: localStorage.getItem('language') ? localStorage.getItem('language') : 'zh-CN',
    area: localStorage.getItem('area') ? localStorage.getItem('area') : 82
  },
  mutations: {
    // 变更配置
    change_config(state, config) {
      state.config = config
    },
    // 设置语言
    setLanguage(state, language) {
      state.language = language
      localStorage.setItem('language', language)
    },
    // 设置一级router效果
    change_first_router(state, isFirstRouter) {
      state.isFirstRouter = isFirstRouter
    },
    // 设置三级router效果
    change_third_router(state, isThirdRouter) {
      state.isThirdRouter = isThirdRouter
    },
    //tf作为主动控制的参数
    switch_loading(state, tf) {
      state.loading = tf
    },
    // 修改区号
    set_area(state, area) {
      console.log(area)
      state.area = area
      localStorage.setItem('area', area)
    },
    // 切换语言
    set_language(state, language) {
      state.language = language
      localStorage.setItem('language', JSON.stringify(language))
    },
    // 变更用户信息
    change_user(state, user) {
      state.user = user
      localStorage.setItem('user', JSON.stringify(user))
    },
    // 变更token
    change_token(state, token) {
      state.token = token
      localStorage.setItem('token', token)
    }
  },
  actions: {},
  modules: {}
})
